#1Uva299 - Train Swapping
#include <bits/stdc++.h>
using namespace std;
int main() {
int t,n,x;
cin>>t;
while(t--){
cin>>n;
vector <int> v;
for(int i=0;i<n;i++){
cin>>x;
v.push_back(x);
}
int ans=0;
for(int i=0;i<v.size();i++){
for(int j=i+1;j<v.size();j++){
if(v[i]>v[j]){
swap(v[i],v[j]);
ans++;
}
}
}
cout<<"Optimal train swapping takes "<<ans<<" swaps."<<endl;
}
}